<template>
	<view>
		<Header :title="title"></Header>
		<view class="toubu">
			
			<kezi :leiji="leiji" :kzxinxi="kzxinxi" @tuisong="tuisongs" :state="state" :userids="userid"></kezi>
			
			<view class="grace-loading" v-if="xiala==0 && leiji.length > 15">上拉加载更多~</view>
			<view class="grace-loading" v-if="xiala==0 && kzxinxi.length > 15">上拉加载更多~</view>
			<view class="grace-loading" v-if="xiala==1">没有更多数据啦~</view>
		</view>
		<requestLoading></requestLoading>
	</view>
</template>

<script>
	import kezi from "@/components/kezi.vue";
	
	export default {
		components: {
			kezi
		},
		data() {
			return {
				state:'',
				title:'',
				sift:",,,全部",
				leiji:[],
				userid:'',
				url:'',
				kzxinxi:[],
				tishi: 1, //展示加载动画
				pagenum:1,
				xiala:999,
			}
		},
		onLoad(option) {
			// 1 推送  0  他的客资
			if(option.state==0){
				this.title='他的客资';
				this.url="wode/hiskz"
			}else{
				this.title='累计推送';
				this.url="wode/pctuisong"
			}
			
			this.state=option.state;
			if(option.userid && option.state==0){
				this.userid=option.userid;
				console.log(this.userid,"this.userid111111")
			}else{
				this.userid='';
			}
			this.tuisong(); 
			// console.log(this.state,"this.this.this.state")
		},
		onShow(){
			// this.tuisong();
		},
		
		onPullDownRefresh() {
		   	this.tishi=2;
			this.xiala=-1;
			this.pagenum=1;
			this.tuisong()
			console.log("触发下拉刷新")
		}, 
		onReachBottom() {
			console.log("上拉加载")
				if(this.xiala===0){
					this.pagenum++;
					this.tishi=1;
					this.tuisong()
				}
		},
		methods: {
			tuisong(){
				let that = this;
						this.configure.ajax({
							url:that.url,	
							tishi:that.tishi,
							data:{
								sift:that.sift,
								userid:that.userid,
								pagenum:that.pagenum
							},
							methods:"POST",
							success:function(res){
								if(that.state==0){
									console.log('0')
									console.log("他的客资")
									if (res.data == null || res.data.length == 0) {
										if(that.pagenum==1){
											that.kzxinxi = []
										}
											that.xiala=1;
											return ;
									}else{
										that.xiala=0;
										if(that.tishi===2){
											that.kzxinxi=res.data;
										}else{
											if(that.pagenum==1){
												that.kzxinxi=res.data;
											}else{
												that.kzxinxi = that.kzxinxi.concat(res.data)
											}
										}
										
									}
								}else{
									console.log('1')
									console.log("累计推送")
									if (res.data.kz == null || res.data.kz.length == 0) {
										if(that.pagenum==1){
											that.leiji = []
										}
											that.xiala=1;
											return ;
									}else{
										that.xiala=0;
										if(that.tishi===2){
											that.leiji=res.data.kz;
										}else{
											if(that.pagenum==1){
												that.leiji=res.data.kz;
											}else{
												that.leiji = that.leiji.concat(res.data.kz)
											}
										}
										
									}
								}
								that.tishi='1111'
								
								that.$forceUpdate();
							}
						})
			},
			tuisongs(sxtype){
				console.log('tuisong')
				this.sift=sxtype;
				this.pagenum=1;
				this.tishi=1;
				this.tuisong()
			}
			
		}
	}
</script>

<style lang="scss" scoped>
	.grace-loading{
		text-align: center;
		color: $qianhui_ziti;
		font-size: 30rpx;
		margin-top: 40rpx;
		margin-bottom: 40rpx;
	}
</style>
